/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : May 18, 2012  12:09:04 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.rental.undue
 * File Name : UndueProcessing.java
 * TODO
 */
package apps.business.process.rental.undue;

import java.util.List;

import jpa.entitys.synchro.staging.FiVcGlpostingOutb;

import org.apache.log4j.Logger;

import promis.utility.CommonService;

import sap.business.fi.outbound.FiVcGlpostingOutbService;

import apps.business.process.SyncProcessorCommons;
import apps.promis.out.common.VwSyncUndueRentAction;

/**
 * @author chatree
 *
 */
public class UndueProcessing extends SyncProcessorCommons {
	
	private static final Logger log = Logger.getLogger(UndueProcessing.class);

	/**
	 * 
	 */
	public UndueProcessing() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * 		String company = "SP"; 
			String project = "SPL_GRAND"; 
			String contractRefNo = "CR-1205-000008-0";
			String documentNo = "IV-1203-000006";

			//IV-1201-000030 //1
			//IV-1202-000004 //2
			//IV-1203-000006 //3
			
			String status = "A";		
			String syncIsstaging = "N";
	 * @param company
	 * @param project
	 * @param contractRefNo
	 * @param documentNo
	 * @param status
	 * @param syncIsstaging
	 * @throws Exception
	 */
	public void Processing(String company, String project, String contractRefNo, String documentNo, String status, String syncIsstaging) throws Exception {
		try{

			//Creatr to STaging 
			UPD_PROMISUseTime(true, false, null);
			List<FiVcGlpostingOutb> value_list = new VwSyncUndueRentAction().CreateToStaging(company, project, contractRefNo, documentNo, status, syncIsstaging);
			UPD_PROMISUseTime(false, true, null);
			System.out.println("Created to Promis. Size=" + CommonService.getSize(value_list));
			
			//Send to SAP
			if(CommonService.getSize(value_list) > 0){
				UPD_SENDUseTime(true, false, value_list.get(0).getInstanceNo());
				new FiVcGlpostingOutbService().SendToSAP(value_list);
				UPD_SENDUseTime(false, true, value_list.get(0).getInstanceNo());
			}			
			System.out.println("Sended to SAP. Size=" + CommonService.getSize(value_list));
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}

	@Deprecated
	private void Start() throws Exception{
		try{
			VwSyncUndueRentAction objj = new VwSyncUndueRentAction();
			
			String company = "SP"; 
			String project = "SPL_GRAND"; 
			String contractRefNo = "CR-1205-000008-0";
			String documentNo = "IV-1203-000006";

			//IV-1201-000030 //1
			//IV-1202-000004 //2
			//IV-1203-000006 //3
			
			String status = "A";		
			String syncIsstaging = "N";
			
			//Creatr to STaging 
			List<FiVcGlpostingOutb> value_list = objj.CreateToStaging(company, project, contractRefNo, documentNo, status, syncIsstaging);
			
			//Send to SAP
			new FiVcGlpostingOutbService().SendToSAP(value_list);
			
		}catch(Exception e){
			log.error(e.getMessage());
			System.err.println(e.getMessage());
			throw e;
		}
	}
	
	
//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		
//		try{
//			
//			UndueProcessing obj = new UndueProcessing();
//			
//			obj.Start();
//			
//		}catch(Exception e)
//		{
//			e.printStackTrace();
//			log.error(e);			
//		}
//	}

}
